<?php
class Espace_pro extends FrontEnd_Controller {

    function Espace_pro() {
        parent::FrontEnd_Controller();
        $this->_data['erreur'] = "";
    }
    function index(){
        $this->offres();
    }
    function offres(){
      is_pro();
      $this->translate();
      $sidebar['1'] = "modules/gestion_pro";
      $idpro = $this->session->userdata('proid');
      $offres=  $this->home_m->get_offres_pro($idpro);
      $this->_data['offres'] = $offres;
      $this->_data['listsidebar'] = $sidebar;
      $this->display_view('pro/offres');
    }

    function disponibles(){
      is_pro();
      $this->translate();
      $sidebar['1'] = "modules/gestion_pro";
      $idpro = $this->session->userdata('proid');
      $dispo=  $this->home_m->get_dispo_pro($idpro);
      $this->_data['dispo'] = $dispo;
      $this->_data['listsidebar'] = $sidebar;
      $this->display_view('pro/dispo');
    }
     function plv($catid=0){
      is_pro();
      $this->translate();
      $sidebar['1'] = "modules/gestion_pro";
       $sidebar['2'] = "modules/plvcat";
      $idpro = $this->session->userdata('proid');
      $plv=  $this->home_m->get_plv_pro($idpro,$catid);
      $cat_plv=  $this->home_m->get_cat_plv_pro();
      $this->_data['plv'] = $plv;
      $this->_data['cat_plv'] = $cat_plv;
      $this->_data['listsidebar'] = $sidebar;
      $this->display_view('pro/plv');
    }

    function connexion(){

          $this->translate();
        $sidebar['1'] = "modules/adresse";
        $this->_data['listsidebar'] = $sidebar;
 if ($this->input->post('submit')) {
             $config = array(
                array('field' => 'ident',
                    'rules' => 'required'
                ),
                array('field' => 'pass',
                    'rules' => 'required|md5'
                )
            );
            $this->form_validation->set_rules($config);

            if ($this->form_validation->run() == TRUE) {
                $data = array(
                    'ident' => $this->input->post('ident'),
                    'pass' => $this->input->post('pass')
                );

                $query = $this->home_m->check_connexion_pro($data);


                if ($query->num_rows() > 0) {
                    $row = $query->row();
                    $this->session->set_userdata('proid', $row->id);

                    $this->session->set_userdata('proname', $row->nom);
                    redirect(site_url("espace_pro/offres"));
                 
                }else {
                    $this->_data['erreur'] = "Identifiant ou mot de passe n'existe pas";
                    $this->display_view('pro/connexion');
                }
            } else
                $this->display_view('pro/connexion');
        } else
            $this->display_view('pro/connexion');
    }
   function deconnexion() {
        $array_items = array('proname' => '', 'proid' => '');
        $this->session->unset_userdata($array_items);
        redirect(base_url() . 'index.php/espace_pro');
    }
}
?>
